import Vue from "vue";
import VueRouter from "vue-router";
import Login from "../views/Login.vue";

Vue.use(VueRouter);

// const originalPush = VueRouter.prototype.push;
// VueRouter.prototype.push = function push(location) {
//   return originalPush.call(this, location).catch(err => err)
// };

const routes = [
    {
        path: "/",
        name: "login",
        component: Login,
    },
    {
        path: "/homeframe",
        name: "home",
        component: () => import("../views/HomeFrame.vue"),
        children: [
            {
                path: "home",
                component: () => import("../views/Home/Home.vue"),
                children: [
                    {
                        path: "system",
                        component: () => import("../views/Home/System.vue"),
                    },
                    {
                        path: "accout",
                        component: () => import("../views/Home/Account.vue"),
                    },
                    {
                        path: "message",
                        component: () => import("../views/Home/Message.vue"),
                    },
                ],
            },
            {
                path: "goods",
                component: () => import("../views/Goods/Home.vue"),
                children: [
                    {
                        path: "list",
                        component: () => import("../views/Goods/List.vue"),
                    },
                    {
                        path: "examine",
                        component: () => import("../views/Goods/Examine.vue"),
                    },
                    {
                        path: "add",
                        component: () => import("../views/Goods/Add.vue"),
                    },
                    {
                        path: "class",
                        component: () => import("../views/Goods/Class.vue"),
                    },
                    {
                        path: "evaluate",
                        component: () => import("../views/Goods/Evaluate.vue"),
                    },
                    {
                        path: "setup",
                        component: () => import("../views/Goods/Setup.vue"),
                    },
                    {
                        path: "stock",
                        component: () => import("../views/Goods/Stock.vue"),
                    },
                    {
                        path: "recovery",
                        component: () => import("../views/Goods/Recovery.vue"),
                    },
                ],
            },
            {
                path: "order",
                component: () => import("../views/Order/Home.vue"),
                children: [
                    {
                        path: "ChecDketails",
                        component: () => import("../views/Order/ChecDketails.vue"),
                    },
                    {
                        path: "list",
                        component: () => import("../views/Order/List.vue"),
                    },
                    {
                        path: "setup",
                        component: () => import("../views/Order/Setup.vue"),
                    },
                    {
                        path: "dfk",
                        component: () => import("../views/Order/dfk.vue"),
                    },
                    {
                        path: "ygb",
                        component: () => import("../views/Order/ygb.vue"),
                    },
                    {
                        path: "ywc",
                        component: () => import("../views/Order/ywc.vue"),
                    },
                    {
                        path: "dfh",
                        component: () => import("../views/Order/dfh.vue"),
                    },
                    {
                        path: "yfh",
                        component: () => import("../views/Order/yfh.vue"),
                    },
                    {
                        path: "refund",
                        component: () => import("../views/Order/Refund.vue"),
                    },
                    {
                        path: "reason",
                        component: () => import("../views/Order/Reason.vue"),
                    },
                ],
            },
            {
                path: "users",
                component: () => import("../views/Users/Home.vue"),
                children: [
                    {
                        path: "list",
                        component: () => import("../views/Users/List.vue"),
                    },
                    {
                        path: "power",
                        component: () => import("../views/Users/Power.vue"),
                    },
                    {
                        path: "label",
                        component: () => import("../views/Users/Label.vue"),
                    },
                ],
            },
            {
                path: "promotion",
                component: () => import("../views/Promotion/Home.vue"),
                children: [
                    {
                        path: "promotion",
                        component: () =>
                            import("../views/Promotion/Promotion.vue"),
                    },
                    {
                        path: "rush",
                        component: () => import("../views/Promotion/Rush.vue"),
                    },
                    {
                        path: "deduction",
                        component: () =>
                            import("../views/Promotion/Deduction.vue"),
                    },
                ],
            },
            {
                path: "operate",
                component: () => import("../views/Operate/Home.vue"),
                children: [
                    {
                        path: "banner",
                        component: () => import("../views/Operate/Banner.vue"),
                    },
                    {
                        path: "special",
                        component: () => import("../views/Operate/Special.vue"),
                    },
                    {
                        path: "scene",
                        component: () => import("../views/Operate/Scene.vue"),
                    },
                    {
                        path: "search",
                        component: () => import("../views/Operate/Search.vue"),
                    },
                    {
                        path: "label",
                        component: () => import("../views/Operate/Label.vue"),
                    },
                    {
                        path: "freight",
                        component: () => import("../views/Operate/Freight.vue"),
                    },
                ],
            },
            {
                path: "statistics",
                component: () => import("../views/Statistics/Home.vue"),
                children: [
                    {
                        path: "transaction",
                        component: () =>
                            import("../views/Statistics/Transaction.vue"),
                    },
                    {
                        path: "goods",
                        component: () =>
                            import("../views/Statistics/Goods.vue"),
                    },
                ],
            },
            {
                path: "jurisdiction",
                component: () => import("../views/Jurisdiction/Home.vue"),
                children: [
                    {
                        path: "role",
                        component: () =>
                            import("../views/Jurisdiction/Role.vue"),
                    },
                    {
                        path: "member",
                        component: () =>
                            import("../views/Jurisdiction/Member.vue"),
                    },
                ],
            },
        ],
    },
];

const router = new VueRouter({
    mode: "history",
    base: process.env.BASE_URL,
    routes,
});

//路由守卫
// router.beforeEach((to, from, next) => {
//     //有sessionStorage执行
//     if (sessionStorage.getItem("store")) {
//         let userMsg = JSON.parse(sessionStorage.getItem("store")).usermsg;
//         //有userMsg执行
//         if (JSON.stringify(userMsg) != "{}") {
//             let jurisData = JSON.parse(userMsg.jurisdiction);
//             let jurisPath = [];
//             if (jurisData) {
//                 jurisData.filter((item) => {
//                     // item.path = item.path.split('/');
//                     // item.path = '/' + item.path[1] + '/' + item.path[2];
//                     jurisPath.push(
//                         item.path.substring(0, item.path.lastIndexOf("/"))
//                     );
//                 });
//                 let toPath = to.path.substring(0, to.path.lastIndexOf("/"));
//                 if (jurisPath.indexOf(toPath) != -1) {
//                     next();
//                 } else {
//                     if (to.path == "/") {
//                         next();
//                     } else {
//                         alert("您未有该模块权限");
//                         next(
//                             JSON.parse(sessionStorage.getItem("store")).nowIndex
//                         );
//                     }
//                 }
//             } else {
//                 next();
//             }
//         } else {
//             if (to.path == "/") {
//                 next();
//             } else {
//                 next("/");
//             }
//         }
//     } else {
//         if (to.path == "/") {
//             next();
//         } else {
//             next("/");
//         }
//     }
// });

export default router;
